<?php
/***
 * Parses an RSS feed and returns the data as an array.
 *
 * TEST: See if this works with other kinds of feeds, atom?
 **/
class Parser {

	var $options = array();

	public function __construct($data = null, $options = array()) {
		$this->options = array_merge($this->options, $options);
	}
	
	public function parse($data) {
		$this->parser = simplexml_load_string($data, null, LIBXML_NOCDATA);
		$this->data = array();
		
		$author = $this->parser->xpath('/rss/channel/title');
		$author = $author[0][0];
		
		foreach ($this->parser->xpath('/rss/channel/item') as $item) {
			$this->data[] = array(
				'title' => (string)$item->title,
				'description' => (string)$item->description,
				'link' => (string)$item->link,
				'published'	=> strtotime((string)$item->pubDate),
				'author' => $author
			);
		}
		
		return $this->data;
	}

}
?>
